package com.gxa.service.shezhiservice.Impl;

import com.gxa.common.R;

import com.gxa.mapper.shezhimapper.KeHuType46Mapper;
import com.gxa.pojo.KeHu;
import com.gxa.pojo.KeHuType;
import com.gxa.service.shezhiservice.KeHuType46Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class KeHuType46ServiceImpl implements KeHuType46Service {

    @Autowired
    private KeHuType46Mapper keHuType46Mapper;
    @Override
    public R selectAllKeHuTypeForPage(int page, int size) {
        R r = new R();
        int index = (page - 1)*size;
        List<KeHuType> keHuTypes = keHuType46Mapper.selectAllKeHuTypeForPage(index,size);
        if (keHuTypes != null){
            r.setCode(200);
            r.setMsg("查询成功！");
            r.setData(keHuTypes);
        }
        return r;
    }

    @Override
    public R selectKeHuTypeByType(int page, int size, String keHuType) {
        R r = new R();
        int index = (page - 1)*size;
        List<KeHuType> keHuTypes = keHuType46Mapper.selectKeHuTypeByType(index,size,keHuType);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(keHuTypes);
        return r;
    }

    @Override
    public R insertKeHuType(KeHuType keHu) {
        R r = new R();
        int res =  keHuType46Mapper.insertKeHuType(keHu);
        r.setCode(500);
        r.setMsg("新增失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("新增成功");
        }
        return r;
    }

    @Override
    public R updateKeHuTypeById(KeHuType keHu) {
        R r = new R();
        int res =  keHuType46Mapper.updateKeHuTypeById(keHu);
        r.setCode(500);
        r.setMsg("更新失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("更新成功");
        }
        return r;
    }

    @Override
    public R deleteKeHuTypeById(int id) {
        R r = new R();
        int res = keHuType46Mapper.deleteKeHuTypeById(id);
        r.setCode(500);
        r.setMsg("删除失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }


}

